<?php

session_start();
include_once('conexion.php');

class Login {

    private $usuario;
    private $contrasena;

    function Login($user, $contra) {
        $this->usuario = $user;
        $this->contrasena = $contra;
    }

    function validar() {

        $sql = "SELECT * FROM  `usuario` WHERE  `contrasena` =  '" . $this->contrasena . "'  AND  `usuario` ='" . $this->usuario . "'";
        $con = new conexion();
        $con->getBD();
        $r = mysql_query($sql, $con->getConexion());
        $log = FALSE;
        $c = mysql_num_rows($r);

        if ($c == 1) {
            $_SESSION['username'] = $this->usuario;
            while ($row = mysql_fetch_array($r)) {
                $_SESSION['id_u'] = $row['id'];
                $_SESSION['nombre'] = $row['nombre'];
                $_SESSION['apellido'] = $row['apellido'];
                $_SESSION['id_p'] = $row['id_proyecto'];
            }
            $log = TRUE;
        }

        return $log;
    }

}

?>